/**
 * window.localStorage
 * author: kaican
 */



 export const LocalStorage = {
  // window.localStorage.setItem
  setItem: (key, value) => {
    if(!window.localStorage) {
      console.log('不支持 localStorage');
      return false;
    }
    if(!key) return false;
    const val = value ? JSON.stringify(value) : JSON.stringify('');
    window.localStorage.setItem(key, val);
  },

  // window.localStorage.getItem
  getItem: (key) => {
    if(!window.localStorage) {
      console.log('不支持 localStorage');
      return undefined;
    }
    if(!key) return undefined;
    const val = window.localStorage.getItem(key)!;
    return JSON.parse(val);
  },

  // window.localStorage.removeItem
  removeItem: (key) => {
    if(!window.localStorage) {
      console.log('不支持 localStorage');
      return false;
    }
    if(!key) return false;
    window.localStorage.removeItem(key);
    return true;
  },
};
